from lib.api.Teacher import tm
from lib.api.SClass import scm
from hytest import STEP, INFO, CHECK_POINT, GSTORE
from config.cfg import *


class Teacher2:
    name = '添加老师2 - tc001002'

    # 测试步骤
    def teststeps(self):
        STEP(1, "添加老师")

        classid = GSTORE['七一班-id']

        ret = tm.add_teacher(username='sun', realname="孙老师", subjectid=SUBJECT_ID_JUNIOR_SCIENCE,
                             classlist=str(classid), phonenumber="12345678",
                             email="sun@163.com", idcardnumber="123123123")

        retAdd = ret.json()
        INFO(retAdd)

        self.teacherid = retAdd['id']

        CHECK_POINT("添加老师检查", retAdd['retcode'] == 0)

        STEP(2, "列出老师")

        ret = tm.list_teacher(subjectid=SUBJECT_ID_JUNIOR_SCIENCE)
        retList = ret.json()

        INFO(retList)

        CHECK_POINT("列出老师检查", retList['retlist'][0]['id'] == self.teacherid)

    def teardown(self):
        tm.delete_teacher(teacherid=self.teacherid)


class Teacher3:
    name = "添加老师3 - tc001003"

    def teststeps(self):
        STEP(1, "添加老师")

        classid = GSTORE['七一班-id']

        ret = tm.add_teacher(username='anran', realname="孙老师", subjectid=SUBJECT_ID_JUNIOR_SCIENCE,
                             classlist=str(classid), phonenumber="12345678",
                             email="sun@163.com", idcardnumber="123123123")

        retAdd = ret.json()
        INFO(retAdd)

        CHECK_POINT("添加老师检查", retAdd['retcode'] == 1)

        STEP(2, "列出老师")

        ret = tm.list_teacher(subjectid=SUBJECT_ID_JUNIOR_SCIENCE)
        retList = ret.json()

        INFO(retList)

        CHECK_POINT("列出老师检查", retList['retlist'] == [])


class Teacher4:
    name = "修改老师1 - tc001051"

    def teststeps(self):
        STEP(1, "修改老师")

        ret = tm.modify_teacher(teacherid=12312, email="12312@qq.com")

        retModify = ret.json()
        INFO(retModify)

        CHECK_POINT("修改老师检查", retModify['retcode'] == 1)


# 返回状态码为500, 服务器异常
class Teacher5:
    name = "修改老师2 - tc001052"

    def teststeps(self):
        STEP(1, "添加班级")

        ret = scm.add_class(gradeid=2, name='八二班', studentlimit=56)
        retAdd = ret.json()

        CHECK_POINT("添加班级检查", retAdd['retcode'] == 0)

        self.classid = retAdd['id']

        STEP(2, "修改老师")

        classid1 = GSTORE['七一班-id']

        ret = tm.modify_teacher(teacherid=GSTORE['安老师-数学老师-id'], realname='孙老师', classlist=f"{self.classid},{classid1}")
        INFO(ret.text)

        retModify = ret.json()

        INFO(retModify)

        CHECK_POINT("修改老师检查", retModify['retcode'] == 0)


    def teardown(self):
        scm.delete_class(classid=self.classid)


class Teacher6:
    name = "删除老师1 - tc001081"

    def teststeps(self):
        STEP(1, "删除不存在的老师")

        ret = tm.delete_teacher(teacherid=12345)
        retDelete = ret.json()

        CHECK_POINT("删除老师检查", retDelete['retcode'] == 404)


class Teacher7:
    name = '删除老师2 - tc001082'

    # 测试步骤
    def teststeps(self):
        STEP(1, "添加老师")

        classid = GSTORE['七一班-id']

        ret = tm.add_teacher(username='sun', realname="孙老师", subjectid=SUBJECT_ID_JUNIOR_SCIENCE,
                             classlist=str(classid), phonenumber="12345678",
                             email="sun@163.com", idcardnumber="123123123")

        retAdd = ret.json()

        self.teacherid = retAdd['id']

        CHECK_POINT("添加老师检查", retAdd['retcode'] == 0)

        STEP(2, "删除老师")

        ret = tm.delete_teacher(teacherid=self.teacherid)
        retDelete = ret.json()

        CHECK_POINT("删除老师检查", retDelete['retcode'] == 0)

